<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<script src="/webjars/jquery/3.5.1/jquery.min.js"></script>

<script type="text/javascript">
    function isForm() {
        var assay_user = $("[name=assayuser]").val();
        if (assay_user == null || assay_user == ""){
            alert("姓名不能为空！")
            return false;
        }

        var phone = $("[name=phone]").val();
        if (phone == null || phone == ""){
            alert("手机号不能为空！")
            return false;
        }

        var card_num = $("[name=cardnum]").val();
        if (card_num == null || card_num == ""){
            alert("身份证不能为空！")
            return false;
        }

        var hospital_id = $("[name=hospitalId]").val();
        if (hospital_id == null || hospital_id == "0"){
            alert("检测机构不能为空！")
            return false;
        }

        var assay_time = $("[name=assaytime]").val();
         alert("日期为："+assay_time)
        var regTime = /\d{4}-\d{2}-\d{2}/;
        if (assay_time.test(regTime)) {

        }else{
            alert("输入时间不正确！")
            return  false;
        }

        return true;
    }

    $(document).ready(function () {

        $("form").submit(function () {
            if (!isForm()) return false;
            return true;
        })

    })

</script>


<body>
    <div>
        <form method="post" action="/addMedica">
            <table>
                <tr>
                    <td>
                        被检查人  <input name="assayuser" type="text">
                    </td>
                </tr>
                <tr>
                    <td>
                        被检查人手机号 <input name="phone" type="text">
                    </td>
                </tr>
                <tr>
                    <td>
                        被检查人身份证号  <input name="cardnum" type="text">
                    </td>
                </tr>
                <tr>
                    <td>
                        检测机构
                        <select name="hospitalId">
                            <option th:value ="0">请选择</option>
                            <option th:each="hosp:${medical2}"
                                    th:value="${hosp.getId()}"
                                    th:text="${hosp.getName()}">
                            </option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        检测日期  <input name="assaytime" type="text">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input value="提交" type="submit">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input value="返回" type="button">
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>
